/*
  学习目标：嵌套路由
*/

import React from 'react';
import { BrowserRouter as Router, Route, NavLink, Switch, Redirect, Link } from 'react-router-dom';
import './index.css';

export default class App extends React.Component {
  render() {
    return (
      <Router>
        <div className="App">
          <h1>app组件</h1>
          <NavLink to="/home" exact>
            调到home
          </NavLink>
          <br />
          <NavLink to="/my">调到我的音乐</NavLink> <br />
          <NavLink to="/friend">调到朋友</NavLink>
          <hr />
          <Switch>
            <Redirect from="/" to="/home" exact />
            <Route path="/home" component={Home}></Route>
            <Route path="/my" component={MyMusic}></Route>
            {/* 了解即可 : 🔔 嵌套路由, 父子级路径可以同名 */}
            <Route path="/friend" component={Friend}></Route>
            <Route component={NotFound}></Route>
          </Switch>
        </div>
      </Router>
    );
  }
}

function Friend() {
  return (
    <div>
      我是朋友组件
      {/* 💥 to属性跳转，从父路径开始写 */}
      <Link to="/friend/f1">朋友孩子1</Link> <br />
      <Link to="/friend/f2">朋友孩子2</Link>
      <br />
      <Link to="/friend/f3">朋友孩子3</Link> <br />
      {/* 用法： 在父组件内， 使用Switch包住Route组件， 设置二级路由匹配规则 */}
      <Switch>
        {/* 💥path路径，从父路径开始写 */}
        <Route path="/friend/f1" exact component={Friend1}></Route>
        <Route path="/friend/f2" component={Friend2}></Route>
        <Route path="/friend/f3" component={Friend3}></Route>
      </Switch>
    </div>
  );
}
const Friend1 = () => <h2>朋友的孩子1</h2>;
const Friend2 = () => <h3>朋友的孩子2</h3>;
const Friend3 = () => <h4>朋友的孩子3</h4>;

const NotFound = () => <h1>404页面</h1>;

function Home() {
  return <h1>我是首页组件</h1>;
}

function MyMusic() {
  return <h1>我是我的音乐件</h1>;
}
